var $ = jquery = layui.jquery;
var layer = layui.layer;
var upload =layui.upload;


//index_banner

$("#addBannerBt").click(function(){
  layer.open({
        type: 1,
        title:"添加推荐",
        content: $('#controladdIndexBanner'),
        area:["500px","540px"],
        btn: ['确定', '取消'],
        yes: function(index, layero){
           alert("点击了确认");
          layer.close(index); 
        }
   });
})
    








$("body").on("click","#index_bannerTable .del",function(){
    layer.confirm('确认要 <span class="red">取消</span> 该推荐吗？', {icon: 3, title:'提示'}, function(index){
        alert("点击了确认");
          layer.close(index);
        });
})


$("body").on("click","#index_bannerTable .edit",function(){
    layer.open({
        type: 1,
        title:"添加推荐",
        content: $('#controlEditIndexBanner'),
        area:["500px","540px"],
        btn: ['确定', '取消'],
        yes: function(index, layero){
           alert("点击了确认");
          layer.close(index); 
        }
   });
})


//图片上传
		 var uploadInst = upload.render({
		    elem: '.upimg'
		    ,url: '/upload/'
		    ,before: function(obj){
		      obj.preview(function(index, file, result){
		        $('#view').attr('src', result); //图片链接（base64）
		      });
		    }
		    ,done: function(res){
		      //如果上传失败
		      if(res.code > 0){
		        return layer.msg('上传失败');
		      }
		      //上传成功
		    }
		    ,error: function(){
		      //演示失败状态，并实现重传
		      // var demoText = $('#demoText');
		      // demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
		      // demoText.find('.demo-reload').on('click', function(){
		      //   uploadInst.upload();
		      // });
		    }
		  });